package com.psp.bu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.psp.bu.controller.res.ListResult;
import com.psp.bu.controller.res.bean.RAreaListBean;
import com.psp.bu.controller.springmvc.req.GetAreaListParam;
import com.psp.bu.service.AddressService;
import com.psp.bu.service.impl.PageResult;


@Component
public class AddressController {

	@Autowired
	AddressService addressServiceImpl;

	public ListResult<RAreaListBean> getAreas(GetAreaListParam param, HttpServletRequest request,
			HttpServletResponse response) {
		String id = param.getAdcode();
		ListResult<RAreaListBean> result = new ListResult<>();
		PageResult<RAreaListBean> resData = addressServiceImpl.getAreas(id);
		if (resData != null) {
			result.setTotalSize(resData.getCount());
			result.setData(resData.getData());
		}
		result.setFlag(true);
		return result;
	}

	public ListResult<RAreaListBean> getAllArea(HttpServletRequest request, HttpServletResponse response) {
		ListResult<RAreaListBean> result = new ListResult<>();
		PageResult<RAreaListBean> resData = addressServiceImpl.getAreas();
		if (resData != null) {
			result.setTotalSize(resData.getCount());
			result.setData(resData.getData());
		}
		result.setFlag(true);
		return result;
	}

}